﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OEMS
{
    /// <summary>
    /// Login form
    /// </summary>
    /// <author>Nick Lauryssen</author>
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {

            int i = 0;
            String[] users = new String[Properties.Settings.Default.Users.Count];
            Properties.Settings.Default.Users.CopyTo( users, 0 );
            String[] passw = new String[Properties.Settings.Default.Passwords.Count];
            Properties.Settings.Default.Passwords.CopyTo(passw, 0);

            //Voor in te loggen: Username=Administrator, Password=Admin *Case sensitive*
            foreach (String user in users)
            {
                if (txtUsername.Text.Equals(user)  && txtPass.Text.Equals(passw[i]))
                {
                    MainForm form = new MainForm(this, user,i);
                    form.Show();
                    lblError.ResetText();
                    break;
                }
                else
                {
                    lblError.Text = "Username or password is incorrect.";
                }
                i++;
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtPass.Text = "Password";
            txtUsername.Text = "Username";
            txtUsername.Focus();
        }

        private void txtUsername_MouseClick(object sender, MouseEventArgs e)
        {
            txtUsername.ResetText();
        }

        private void txtPass_MouseClick(object sender, MouseEventArgs e)
        {
            txtPass.ResetText();
        }

        private void txtPass_Leave(object sender, EventArgs e)
        {
            if(txtPass.Text == "")
                txtPass.Text = "Password";
        }

        private void txtUsername_Leave(object sender, EventArgs e)
        {
            if (txtUsername.Text == "")
                txtUsername.Text = "Username";
        }
    }
}
